'''
二分查找
猜数字，电话本，数据库手机号查询
'''


def binary_search(list, item):
    """二分查找实现
    :arg list 待查找的数字所在的列表
    :arg item 待查找的数字

    :returns 数字=>数字在列表中的索引， None=>没有找到
    """
    low = 0
    high = len(list) - 1
    findCount = 0

    while low <= high:
        findCount += 1
        mid = int((low + high) / 2)
        guess = list[mid]
        if guess == item:
            print(findCount)
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    print(findCount)
    return None


if __name__ == '__main__':
    list100 = [s for s in range(100)]
    print(list100)
    print(binary_search(list100, 1))
